package basis;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * 约瑟夫环
 * 
 * @author 71936_000
 * 
 */
public class Demo3_Joseph {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		System.out.println("输入总人数");
		int i = sc.nextInt();
		System.out.println("输入从几开始？");
		int j = sc.nextInt();
		System.out.println("数到几的人出列？");
		int k = sc.nextInt();
		String str[] = new String[i];

		List<Integer> all = new ArrayList<Integer>();
		for (int x = 1; x <= i; x++) { // 加数字到集合里面
			all.add(x);
		}
		System.out.println(all);
		int y = j - 1; // 从y角标开始计数，即从j开始
		while (all.size() > 0) {
			y = y + k;
			y = y % (all.size()) - 1;
			if (y < 0) {
				System.out.println(all.get(all.size() - 1));
				all.remove(all.size() - 1);
				y = 0;
			} else {
				System.out.println(all.get(y));
				all.remove(y);
			}
		}
	}
}
